/**
 * Witontek.com.
 * Copyright (c) 2012-2017 All Rights Reserved.
 */
package com.witon.witontool.core.model.db.converter;

import java.util.ArrayList;
import java.util.List;

import com.witon.witontool.common.dal.common.PageList;
import com.witon.witontool.common.dal.pg.dbo.DbConfigDo;
import com.witon.witontool.core.model.db.model.DbConfig;

/**
 * 
 * @author Long
 * @version $Id: DbConfigConverter.java, v 0.1 2017年6月29日 下午3:29:45  xiaolong.ma  Exp $
 */
public class DbConfigConverter {
    public static DbConfigDo convert(DbConfig model) {
        if (model == null) {
            return null;
        }
        DbConfigDo ret = new DbConfigDo();
        ret.setId(model.getId());
        ret.setName(model.getName());
        ret.setDevUrl(model.getDevUrl());
        ret.setDevUsername(model.getDevUsername());
        ret.setDevPassword(model.getDevPassword());
        ret.setProdUrl(model.getProdUrl());
        ret.setProdUsername(model.getProdUsername());
        ret.setProdPassword(model.getProdPassword());
        ret.setStatus(model.getStatus());
        ret.setGmtCreate(model.getGmtCreate());
        ret.setGmtModify(model.getGmtModify());
        return ret;
    }

    public static DbConfig convert(DbConfigDo modelDo) {
        if (modelDo == null) {
            return null;
        }
        DbConfig ret = new DbConfig();
        ret.setId(modelDo.getId());
        ret.setName(modelDo.getName());
        ret.setDevUrl(modelDo.getDevUrl());
        ret.setDevUsername(modelDo.getDevUsername());
        ret.setDevPassword(modelDo.getDevPassword());
        ret.setProdUrl(modelDo.getProdUrl());
        ret.setProdUsername(modelDo.getProdUsername());
        ret.setProdPassword(modelDo.getProdPassword());
        ret.setStatus(modelDo.getStatus());
        ret.setGmtCreate(modelDo.getGmtCreate());
        ret.setGmtModify(modelDo.getGmtModify());
        return ret;
    }

    public static List<DbConfig> convertList(List<DbConfigDo> doList) {
        if ((doList == null) || (doList.size() < 1)) {
            return null;
        }
        List<DbConfig> list = new ArrayList<DbConfig>();
        for (DbConfigDo modelDo : doList) {
            DbConfig model = convert(modelDo);
            list.add(model);
        }
        return list;
    }

    public static PageList<DbConfig> convertPageList(PageList<DbConfigDo> doPageList) {
        List<DbConfig> modelList = convertList(doPageList.getResultList());
        PageList<DbConfig> pageList = new PageList<DbConfig>();
        pageList.setPageSize(doPageList.getPageSize());
        pageList.setPageNum(doPageList.getPageNum());
        pageList.setMaxPageNum(doPageList.getMaxPageNum());
        pageList.setTotalCount(doPageList.getTotalCount());
        pageList.setResultList(modelList);
        return pageList;
    }

}
